﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CollegeShop.Api.BaseComponent;
using CollegeShop.Api.ViewObject.Base;
using CollegeShop.Api.Entity;
using System.Data;
using CollegeShop.Api.Framework;

namespace CollegeShop.Api.Repository
{
    public class BaseBiz : IComponent
    {
        private BaseBiz() { }
        public List<DormitoryVO> GetAllDormitory(int college)
        {
            return WithCache("BaseBiz.GetAllDormitory", () =>
            {
                var dt = new CollegeShop.Api.Infrastructure.t_dormitory().GetList(college, "1=1");
                if (dt.Tables.Count == 1)
                {
                    List<DormitoryVO> list = new List<DormitoryVO>();
                    foreach (DataRow row in dt.Tables[0].Rows)
                    {
                        list.Add(new DormitoryVO()
                        {
                            DormitoryName = row["dormitoryname"].ToString(),
                            Id = row["Id"].ToInt32(0)
                        });
                    }
                    return list;
                }
                return null;
            }, 6000);
        }
        public static BaseBiz Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (key)
                    {
                        if (instance == null)
                        {
                            instance = new BaseBiz();
                        }
                    }
                }
                return instance as BaseBiz;
            }
        }
    }
}
